dojo.declare("MHomeMenuPg", wm.Page, {
    start: function() {

    },
    "preferredDevice": "phone",

    picture1Click: function(inSender) {
        this.lvCategories.filter.setValue('department.departmentName', 'Kitchen');
        this.lvCategories.update();
        this.layer2.activate();

    },
    list1Select: function(inSender, inItem) {
        this.lvItems.update();
        this.layer3.activate();
    },
    picture2Click: function(inSender) {
        this.lvCategories.filter.setValue('department.departmentName', 'Refridgerator');
        this.lvCategories.update();
        this.layer2.activate();
    },
    picture3Click: function(inSender) {
        this.lvCategories.filter.setValue('department.departmentName', 'Bedroom');
        this.lvCategories.update();
        this.layer2.activate();
    },
    bAddQtyClick: function(inSender) {

        if (this.txtQuantity) {
            // alert(isNaN(this.txtQuantity.getDataValue()));
            if (this.txtQuantity.getDisplayValue()) {
                this.txtQuantity.setDisplayValue(+this.txtQuantity.getDataValue() + 1);
            } else {
                this.txtQuantity.setDisplayValue(1);
            }

        }
        /**
         var rowIndex = this.list2.selectedItem.getData().itemId;
         
         for (var count = 0; count < this.lvItems.getCount(); count++) {
         
         var vItem = this.lvItems.getItem(count);
         
         if (vItem.data.itemId === rowIndex) {
         if (vItem.data.tax) {
         vItem.data.tax = vItem.data.tax + 1;
         this.txtQuantity.setDataValue(vItem.data.tax);
         } else {
         vItem.data.tax = 1;
         this.txtQuantity.setDataValue(1);
         }
         
         this.lvItems.setItem(count, vItem);
         }
         }**/

    },
    bRemoveQtyClick: function(inSender) {

        if (this.txtQuantity) {
            if (this.txtQuantity.getDisplayValue() > 0) {
                this.txtQuantity.setDisplayValue(+this.txtQuantity.getDisplayValue() - 1);
            } else {
                this.txtQuantity.setDisplayValue(0);
            }

        }
        /**
         var rowIndex = this.list2.selectedItem.getData().itemId;
         
         for (var count = 0; count < this.lvItems.getCount(); count++) {
         
         var vItem = this.lvItems.getItem(count);
         
         if (vItem.data.itemId === rowIndex) {
         if (vItem.data.tax) {
         vItem.data.tax = vItem.data.tax - 1;
         this.txtQuantity.setDataValue(vItem.data.tax);
         } else {
         vItem.data.tax = 1;
         this.txtQuantity.setDataValue(1);
         }
         
         this.lvItems.setItem(count, vItem);
         }
         }**/
        //var quantity=this.txtQuantity.getDataValue();
        // if(!quantity)
        //    quantity=0;
        //    quantity=quantity-1;
        //    this.txtQuantity.setDataValue(quantity);	
    },
    list2Select: function(inSender, inItem) {

        var quantity = this.list2.selectedItem.getData().quantity;
        if (quantity) {
            this.txtQuantity.setDisplayValue(quantity);
        } else {
            this.txtQuantity.setDisplayValue(1);
        }

        /**
         
         for (var count = 0; count < this.lvItems.getCount(); count++) {
         
         var vItem = this.lvItems.getItem(count);
         
         if (vItem.data.itemId === rowIndex) {
         if (vItem.data.tax) {
         
         this.txtQuantity.setDataValue(vItem.data.tax);
         } else {
         //vItem.data.tax = 1;
         this.txtQuantity.setDataValue(1);
         }
         this.lvItems.setItem(count, vItem);
         //this.lvItems.setItem(count, vItem);
         }
         }**/
        this.designableDialog1.show();
    },
    bAddToCartClick: function(inSender) {

        if (+this.txtQuantity.getDataValue() > 0) {

            var selItemId = this.list2.selectedItem.getData().itemId;

            for (var count = 0; count < this.lvItems.getCount(); count++) {

                var vItem = this.lvItems.getItem(count);

                if (vItem.data.itemId === selItemId) {


                    if (app.vCartItems.getCount() > 0) {
                        var isMatchFound = false;
                        var cartCount = app.vCartItems.getCount();
                        for (var count1 = 0; count1 < cartCount; count1++) {
                            var vcartItem = app.vCartItems.getItem(count1);
                            if (vcartItem.data.itemId === selItemId) {
                                vcartItem.data.quantity = +this.txtQuantity.getDataValue();
                                vItem.data.quantity = this.txtQuantity.getDataValue();
                                app.vCartItems.setItem(count1, vcartItem);
                                this.lvItems.setItem(count, vItem);
                                isMatchFound = true;


                            }
                        }
                        if (!isMatchFound) {
                            vItem.data.quantity = +this.txtQuantity.getDataValue();
                            this.lvItems.setItem(count, vItem);
                            app.vCartItems.addItem(vItem);

                        }

                    } else {
                        vItem.data.quantity = +this.txtQuantity.getDataValue();
                        this.lvItems.setItem(count, vItem);
                        app.vCartItems.addItem(vItem, count);

                        // var vItem1 = this.lvItems.getItem(count);
                        // alert(vItem1.data.quantity);
                    }
                }



            }
        }

        this.designableDialog1.hide();
    },


    list2PHONE_COLUMNFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {
        //	var itemsFormat=' "<div class='MobileRow'>" +"Item Name: " + ${itemName} + "</div>"+ "<div class='MobileRow'>" +"Unit: " + ${unit} + "</div>"+ "<div class='MobileRow'>" +"Item Price: " + ${itemPrice} + "</div>"';
        //      return itemsFormat;
    },
    list2ItemIdFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {

        var itemsFormat = "<div class='MobileRow'>" + " " + rowObj.itemName + "</div>" + "<div class='MobileRow'>" + " " + rowObj.unit + "</div>"

        + "<div class='MobileRow'>" + " Price: " + rowObj.itemPrice + " " + rowObj.currency + "</div>";


        return itemsFormat;
    },



    button4Click1: function(inSender) {
        //	this.list2.clearSelection();
    },
    _end: 0
});